package ru.spbu.math.seabattle.client.jms.gui;

import java.awt.Rectangle;

import javax.jms.JMSException;
import javax.swing.JFrame;

import ru.spbu.math.seabattle.client.jms.SeaBattleClientWrapper;

public class LoginFormGUI extends JFrame {

	private static final long serialVersionUID = 1L;

	private ExtendedContainer content = new ExtendedContainer(this
			.getContentPane());
	private static final String SERVER_URL = "localhost:9001";

	private final SeaBattleClientWrapper clientWrapper;
	
	private FormComponent form;

	public LoginFormGUI(SeaBattleClientWrapper clientWrapper) {
		
		super("Connect to game server");
		
		this.clientWrapper = clientWrapper;
		this.setBounds(Constants.getLoginFrameRectangle());
		this.setResizable(false);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		content.setLayout(null);

		form = new FormComponent(this, SERVER_URL);
		form.setBounds(new Rectangle(10, 10, 0, 0));
		content.add(form);
	}

	public void connect(String url, String name) {
		
		try {
			form.setInConnection(true);
			clientWrapper.connect(url, name);
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
